<!--
 * @Author: yan_hai_dong 891236760@qq.com
 * @Date: 2022-08-17 13:09:30
 * @LastEditors: yan_hai_dong 891236760@qq.com
 * @LastEditTime: 2022-08-18 14:52:38
 * @FilePath: \app\src\views\el\css\input\conponents\loginInput.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <div class="my-input">
    <input :class="{active:_value != ''}" :id="inputId" type="text" v-model="_value" />
    <label :for="inputId">{{ label }}</label>
    <div class="bar"></div>
  </div>
</template>

<script>
export default {
  model: {
    prop: "value",
    event: "input",
  },
  props: {
    label: {
      default: "",
      type: [Number, String],
    },
    value: {
      default: "",
      type: [Number, String],
    },
  },
  data() {
    return {
      inputId: `${+new Date()}${Math.random()} `,
    };
  },
  computed: {
    _value: {
      get() {
        return this.value;
      },
      set(val) {
        this.$emit("input", val);
      },
    },
  },
};
</script>

<style lang="less" scoped>
@color: cadetblue;
@activeColor: #526421;
@labelH: 28px;
@inputH: 40px;
@ss: 0.4s;
.my-input {
  position: relative;
  padding: @labelH 0 0;
  label {
    line-height: @labelH;
    color: #ccc;
    position: absolute;
    left: 10px;
    top: calc(@labelH + @inputH / 2);
    transform: translate(0, -50%);
    transition: all @ss ease;
    font-size: 14px;
  }
  input {
    border: none;
    height: @inputH;
    width: 100%;
    border-radius: 4px;
    text-indent: 4px;
    &:focus,
    &.active {
      & ~ label {
        color: @color;
        top: 0;
        left: 0;
        transform: translate(0, 0);
        font-size: 16px;
        font-weight: bold;
      }
      & ~ .bar {
        width: 100%;
      }
    }
  }
  .bar {
    position: absolute;
    transition: all @ss ease;
    bottom: 0;
    width: 0;
    left: 50%;
    transform: translate(-50%, 0);
    height: 2px;
    background-color: @color;
  }
}
</style>